package com.android.xunxian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.xunxian.entry.Device;
import com.oa.android.R;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by 设备 on 2016/7/3.
 */
public class DeviceAdpter extends BaseAdapter {

    private Context context;
    private List<Device> deviceList;

    public DeviceAdpter(Context context, List<Device> deviceList) {
        this.context = context;
        this.deviceList = deviceList;
    }


    @Override
    public int getCount() {
        return deviceList.size();
    }

    @Override
    public Object getItem(int position) {
        return deviceList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.device_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.name.setText(deviceList.get(position).getDEVNAME());
        viewHolder.bh.setText(deviceList.get(position).getKINDNAME());

        if (deviceList.get(position).getSTATUS() != null && deviceList.get(position).getSTATUS().equals("1")) {
            viewHolder.onles.setImageResource(R.mipmap.zc_img);
        } else {
            viewHolder.onles.setImageResource(R.mipmap.error_img);
        }
        if (deviceList.get(position).getISOK() != null && deviceList.get(position).getISOK().equals("1")) {
            viewHolder.state.setImageResource(R.mipmap.zc_img);
        } else {
            viewHolder.state.setImageResource(R.mipmap.error_img);
        }


        return convertView;
    }




    class ViewHolder {
        @InjectView(R.id.name)
        TextView name;
        @InjectView(R.id.bh)
        TextView bh;
        @InjectView(R.id.onles)
        ImageView onles;
        @InjectView(R.id.state)
        ImageView state;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
